package com.zzz.demo01;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.google.common.collect.ImmutableList;
/**
 * @author zhuzhizun
 * @date 2021/7/19
 */
public class UnmodifiableList {
    public static void main(String[] args) {


        ArrayList<String> arrayList = new ArrayList<>(Arrays.asList("张三","李四","王五"));
        List<String> unmodifiableList = Collections.unmodifiableList(arrayList);
        arrayList.add("zzz");
        //张三 李四 王五 zzz
        unmodifiableList.forEach(s -> System.out.print(s+" "));

        System.out.println("\n------------------");

        List<String> list = new ArrayList<>();
        list.add("沉默王二");
        ImmutableList<String> lists = ImmutableList.copyOf(list);
        list.add("沉默王三");
        list.add("沉默王四");
        //沉默王二
        lists.forEach(v -> System.out.print(v+" "));
//        unmodifiableList.add("zzz");



    }
}
